#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef unsigned long       DWORD;
typedef unsigned short      WORD;
typedef char				byte;
#define DISP_BITS 11
#define COUNT_BITS 3
#define INDEX_BIT_COUNT       9
#define LENGTH_BIT_COUNT      4 
#define WINDOW_SIZE           ( 1 << INDEX_BIT_COUNT ) //here is 512
#define RAW_LOOK_AHEAD_SIZE   ( 1 << LENGTH_BIT_COUNT ) 
#define BREAK_EVEN            ( ( 1 + INDEX_BIT_COUNT + LENGTH_BIT_COUNT ) / 9 ) 
 
#define LOOK_AHEAD_SIZE       (RAW_LOOK_AHEAD_SIZE + BREAK_EVEN)
#define TREE_ROOT             WINDOW_SIZE 
#define END_OF_STREAM         0 
#define UNUSED                0 
#define MOD_WINDOW( a )       ( ( a ) & ( WINDOW_SIZE - 1 ) ) 
//0-9
#define MaxList 19
class Dict
{
private:
	int *secSize;		//the size of data section,start at 1
	char* *dicIndex;	//the first and last words of each section,start at 0
	char* dec_buf;
	long dec_len;
	bool open;
	long curSecIndex;
	unsigned char window[WINDOW_SIZE ];
	FILE *fin;
	char* getLine(FILE *in);
	WORD (*SwapWord)(WORD r);
	DWORD (*SwapLong)(DWORD r);
	int SwapChoose();
	long SearchSector(const char* queryWord);
	long GetSector(long secIndex, char** enc);
public:
	char dictName[32];
	long secNumber;
	Dict()
	{
		curSecIndex=-1;
		secSize=NULL;
		fin=NULL;
		dec_buf=NULL;
		open=false;
	};
	~Dict()
	{
		CloseDict();
	};
	bool OpenDict(char* fileName);
	int GetExp(const char* queryWord, char **exp);
	int GetWordList(const char* queryWord, char ***list);
	void CloseDict();
	int Decompresslzss(char* enc,long len,char** dec);
};
